home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Exchange
/
CD Exchange - Volume 1.iso
/
graphics
/
utils
/
ham8-jpeg
/
source
/
al-j.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-20
|
13KB
|
570 lines
/*
* Al-j.c Michael Saunby M.Saunby@reading.ac.uk
*
* Release 1.1 December 1992 Jpeg viewer using Albert HAM8 public screen and
* Independent JPEG groups jpeg decompressor.
*/
#define PROG_NAME "Al-J JPEG Viewer"
#define COPYRIGHT_MESSAGE "Version 1.1\nDecember 1992\n\nCopyright © 1992\n\
Michael Saunby\n\
\nThis program is based in part\n\
on the work of the Independent\n\
JPEG Group"
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <graphics/gfxbase.h>
#include <graphics/displayinfo.h>
#include <intuition/screens.h>
#include <dos/dosextens.h>
#include <dos/dosasl.h>
#include <libraries/gadtools.h>
#include <clib/asl_protos.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/layers_protos.h>
#include <clib/graphics_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/dos_protos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "display24.h"
/* Values greater than 1 give bad pixels, why? */
#define ARRAY24_MAX_ROWS 1
/*
* ReadArgs() template
*/
#define TEMPLATE "NAME"
#define OPT_NAME 0
#define OPT_COUNT 1
int JPEG_restart = 0; /* set to 1 for New file */
struct IntuitionBase *IntuitionBase = NULL;
struct GfxBase *GfxBase = NULL;
struct Library *GadToolsBase = NULL;
struct Library *AslBase = NULL;
extern struct ExecBase *SysBase;
/* following for 24 bit put row */
SHORT ham8_line; /* screen line number to draw at */
UBYTE *ham8_pens = NULL;
struct RastPort ham8_temprp;
struct BitMap *temp_bm = NULL;
struct Screen *screen = NULL;
struct FileRequester *filereq = NULL;
struct BitMap *bitmap = NULL;
struct Window *window = NULL;
struct Menu *menu;
struct Gadget *gadgets, *horprop = NULL, *vertprop = NULL;
void *vi;
ULONG allocsignal;
/* gadget ids */
#define HORPROP 1
#define VERTPROP 2
/* current x and y offsets */
LONG scroll_x = 0;
LONG scroll_y = 0;
LONG window_max_w;
LONG window_max_h;
struct EasyStruct failedES =
{sizeof (struct EasyStruct), 0, PROG_NAME,
"%s", "OK",};
#define OPEN 1
#define ABOUT 2
#define QUIT 3
struct NewMenu prj_menu[] =
{
{NM_TITLE, "Project", 0, 0, 0, 0,},
{NM_ITEM, "Open...", "O", 0, 0, (void *) OPEN,},
{NM_ITEM, NM_BARLABEL, 0, 0, 0, 0,},
{NM_ITEM, "About...", "?", 0, 0, (void *) ABOUT,},
{NM_ITEM, "Quit", "Q", 0, 0, (void *) QUIT,},
{NM_END, NULL, 0, 0, 0, 0,},
};
void
Cleanup ()
{
if (screen)
UnlockPubScreen (NULL, screen);
screen = NULL;
if (window)
{
ReleasePens (&(window->WScreen->ViewPort));
FreeVisualInfo (vi);
CloseWindow (window);
gadgets = NULL;
}
window = NULL;
if (menu)
ClearMenuStrip (window);
menu = NULL;
if (horprop)
DisposeObject (horprop);
horprop = NULL;
if (vertprop)
DisposeObject (vertprop);
vertprop = NULL;
if (ham8_pens)
FreeMem (ham8_pens, ((temp_bm->BytesPerRow << 3) * temp_bm->Rows));
ham8_pens = NULL;
if (temp_bm)
FreeBitMap (temp_bm);
temp_bm = NULL;
if (bitmap)
FreeBitMap (bitmap);
bitmap = NULL;
if (!JPEG_restart)
{
if (filereq)
FreeAslRequest (filereq);
filereq = NULL;
if (AslBase)
CloseLibrary (AslBase);
AslBase = NULL;
if (GadToolsBase)
CloseLibrary (GadToolsBase);
GadToolsBase = NULL;
if (IntuitionBase)
CloseLibrary ((struct Library *) IntuitionBase);
IntuitionBase = NULL;
if (GfxBase)
CloseLibrary ((struct Library *) GfxBase);
GfxBase = NULL;
}
}
void
Quit (char whytext[], UBYTE failcode)
{
EasyRequest (NULL, &failedES, NULL, whytext);
Cleanup ();
exit (failcode);
}
void
UserWait ()
{
struct IntuiMessage *msg;
struct Gadget *gadget;
BOOL abort = FALSE;
UWORD class, code;
LONG new_x, new_y;
SetGadgetAttrs (horprop, window, NULL,
GA_Disabled, FALSE,
TAG_END);
SetGadgetAttrs (vertprop, window, NULL,
GA_Disabled, FALSE,
TAG_END);
do
{
WaitPort (window->UserPort);
while (msg = GT_GetIMsg (window->UserPort))
{
code = msg->Code;
class = msg->Class;
gadget = (struct Gadget *) msg->IAddress;
GT_ReplyIMsg (msg);
switch (class)
{
case IDCMP_MENUPICK:
switch ((UWORD) MENU_USERDATA (ItemAddress (menu, code)))
{
case QUIT:
abort = TRUE;
break;
case OPEN:
JPEG_restart = TRUE;
abort = TRUE;
break;
case ABOUT:
EasyRequest (window, &failedES,
NULL,
COPYRIGHT_MESSAGE);
break;
}
break;
case IDCMP_CLOSEWINDOW:
abort = TRUE;
break;
case IDCMP_SIZEVERIFY:
case IDCMP_NEWSIZE:
SetGadgetAttrs (vertprop, window, NULL,
PGA_Visible, window->GZZHeight,
TAG_END);
SetGadgetAttrs (horprop, window, NULL,
PGA_Visible, window->GZZWidth,
TAG_END);
break;
case IDCMP_GADGETUP:
switch (gadget->GadgetID)
{
case HORPROP:
GetAttr (PGA_Top, horprop, &new_x);
ScrollLayer (0L, window->RPort->Layer, new_x - scroll_x, 0);
scroll_x = new_x;
WindowLimits (window, 0, 0, window_max_w - scroll_x, 0);
break;
case VERTPROP:
GetAttr (PGA_Top, vertprop, &new_y);
ScrollLayer (0L, window->RPort->Layer, 0, new_y - scroll_y);
scroll_y = new_y;
WindowLimits (window, 0, 0, 0, window_max_h - scroll_y);
break;
}
break;
default:
/*
* EasyRequest(window, &failedES, NULL, "Bogus message
* sorry!");
*/
break;
}
}
} while (abort == FALSE);
Cleanup ();
}
char *
Startup (char *namebuf)
{
char *ret_code = NULL;
LONG result[OPT_COUNT] =
{0};
struct RDArgs *rda;
if (!JPEG_restart)
{
if ((GfxBase =
(struct GfxBase *) OpenLibrary ("graphics.library", 36)) == NULL)
Quit ("graphics.library is too old <V36", 25);
if ((IntuitionBase =
(struct IntuitionBase *) OpenLibrary ("intuition.library", 36)) == NULL)
Quit ("intuition.library is too old <V36", 25);
if ((AslBase = OpenLibrary ("asl.library", 36)) == NULL)
Quit ("asl.library is too old <V36", 25);
if ((GadToolsBase = OpenLibrary ("gadtools.library", 36)) == NULL)
Quit ("gadtools.library is too old <V36", 25);
if ((filereq =
(struct FileRequester *) AllocAslRequestTags (ASL_FileRequest,
ASLFR_PubScreenName, HAM8_ALBERT_NAME,
TAG_END))
== NULL)
Quit ("could not build file requster", 25);
rda = ReadArgs (TEMPLATE, result, NULL);
if (result[OPT_NAME])
{
strcpy (namebuf, (UBYTE *) result[OPT_NAME]);
ret_code = namebuf;
}
FreeArgs (rda);
}
JPEG_restart = FALSE;
if (ret_code == NULL)
{
struct Screen *screen;
/*
* Opening the File Requester does not bring screen to front. Passing
* the name ie. UnlockPubscreen(HAM8_ALBERT_NAME, NULL) is allowed
* but not recommended. I haven't tried it.
*/
if ((screen = LockPubScreen (HAM8_ALBERT_NAME)) != NULL)
{
ScreenToFront (screen);
UnlockPubScreen (NULL, screen);
}
if (AslRequest (filereq, 0L))
{
if(filereq->rf_Dir[strlen(filereq->rf_Dir)-1] == ':')
sprintf (namebuf, "%s%s", filereq->rf_Dir, filereq->rf_File);
else
sprintf (namebuf, "%s/%s", filereq->rf_Dir, filereq->rf_File);
ret_code = namebuf;
}
}
ham8_line = 0;
return (ret_code);
}
void
CreateWindow (UWORD width, UWORD height)
{
int pen_errors;
struct Gadget **tmpgad;
if ((menu = CreateMenus (prj_menu, GTMN_FrontPen, 1, TAG_DONE)) == NULL)
Quit ("could not build menu", 25);
if ((screen = LockPubScreen (HAM8_ALBERT_NAME)) == NULL)
Quit ("could not find screen", 25);
if ((bitmap = AllocBitMap (width, height, 8, BMF_DISPLAYABLE | BMF_CLEAR,
NULL)) == NULL)
Quit ("could not allocate bitmap", 25);
gadgets = NULL;
tmpgad = &gadgets;
/* Create scroller gadgets */
horprop = (struct Gadget *) NewObject (NULL, "propgclass",
GA_Immediate, TRUE,
GA_BottomBorder, TRUE,
GA_GZZGadget, TRUE,
GA_RelVerify, TRUE,
PGA_Freedom, FREEHORIZ,
PGA_Borderless, FALSE,
PGA_NewLook, TRUE,
GA_RelBottom, -10,
GA_RelWidth, -21,
GA_Left, 3,
GA_Height, 7,
PGA_